package tests.delete;

import static org.junit.Assert.fail;

import model.Budget;
import model.BudgetFactory;
import model.Line;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/*
 * 
 * Attempts to delete 1 specific line of a budget with 2 lines
 * 
 */

public class LineDeleteTest01
{
	Budget budget;
	Line line1;
	Line line2;
	BudgetFactory factory;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{
		factory = new BudgetFactory();
		
		//Create a budget
        budget = (Budget) factory.create();
        budget.setName("Test budget");
        
        budget.setDescription("This is a delete test budget.");
        
        line1 = (Line) budget.createLine();
        line2 = (Line) budget.createLine();
        
        line1.setName("Line 1 delete test");
        line2.setName("Line 2 delete test");
        
        budget.add(line1);
        budget.commit();
        budget.add(line2);
        budget.commit();
		
	}

	@After
	public void tearDown() throws Exception
	{    
	}

	@Test
	public void test()
	{
		 try
		 {
            budget.delete(line1);
            
            Boolean successful = budget.commit();
            
            if(!successful)
            	fail("Line failed to delete");  
        }
        catch(Exception e)
        {
            fail("Creating Budget failed with exception: " + e);
        }
	}
}